﻿using System;
using System.Collections.Generic;
using Ext.Net;
using BLL;
using Model;
using System.Xml;
using System.Xml.Xsl;

namespace Web.View.d50_mzmxMenu
{
    public partial class Default : UIPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        //绑定Grid
        protected void d50_mzmx_DataBind(object sender, StoreRefreshDataEventArgs e)
        {
            d50_mzmxMgr mgr = new d50_mzmxMgr();
            e.Total = int.Parse(mgr.GetRecordCount_d50_mzmx(e.Parameters[d50_mzmx_Filter.ParamPrefix]));
            IList<d50_mzmx> list = mgr.FindAllByPage_d50_mzmx(e.Start.ToString(), e.Limit.ToString(), e.Parameters[d50_mzmx_Filter.ParamPrefix]);
            d50_mzmx_MainStore.DataSource = list;
            d50_mzmx_MainStore.DataBind();
        }
        //删除数据
        protected void BtnDel_Click(object sender, DirectEventArgs e)
        {
            d50_mzmxMgr mgr = new d50_mzmxMgr();
            RowSelectionModel sm = d50_mzmx_Grid.SelectionModel.Primary as RowSelectionModel;
            foreach (SelectedRow row in sm.SelectedRows)
            {
                d50_mzmx _d50_mzmx = new d50_mzmx();
                _d50_mzmx.zyid = row.RecordID;//int.Parse(row.RecordID);
                if (mgr.Del_d50_mzmx(_d50_mzmx))
                {
                    log.Debug("d50_mzmx中执行了删除，并成功");
                    X.Msg.Notify("成功", "<font color='green'>已经成功删除选中的记录</font>").Show();
                }
                else
                    X.Msg.Notify("失败", "<font color='green'>删除记录失败，请您重试！</font>").Show();
            }
            d50_mzmx_Grid.Reload();
        }
        protected void BtnSave_Click(object sender, DirectEventArgs e)
        {
            d50_mzmxMgr mgr = new d50_mzmxMgr();
            d50_mzmx _d50_mzmx = new d50_mzmx();
            if (Hid.Text.Length > 0)
                _d50_mzmx = mgr.FindById_d50_mzmx(int.Parse(Hid.Text));
            
			_d50_mzmx.rowid = Txtrowid.Text.Trim();
			_d50_mzmx.zyh = Txtzyh.Text.Trim();
			_d50_mzmx.fyrq = Txtfyrq.Text.Trim();
			_d50_mzmx.fyxh = Txtfyxh.Text.Trim();
			_d50_mzmx.fymc = Txtfymc.Text.Trim();
			_d50_mzmx.ypcd = Txtypcd.Text.Trim();
			_d50_mzmx.ypgg = Txtypgg.Text.Trim();
			_d50_mzmx.dw = Txtdw.Text.Trim();
			_d50_mzmx.jx = Txtjx.Text.Trim();
			_d50_mzmx.fysl = Txtfysl.Text.Trim();
			_d50_mzmx.fydj = Txtfydj.Text.Trim();
			_d50_mzmx.zjje = Txtzjje.Text.Trim();
			_d50_mzmx.zfje = Txtzfje.Text.Trim();
			_d50_mzmx.ysgh = Txtysgh.Text.Trim();
			_d50_mzmx.srgh = Txtsrgh.Text.Trim();
			_d50_mzmx.qrgh = Txtqrgh.Text.Trim();
			_d50_mzmx.fybq = Txtfybq.Text.Trim();
			_d50_mzmx.fyks = Txtfyks.Text.Trim();
			_d50_mzmx.zxks = Txtzxks.Text.Trim();
			_d50_mzmx.jfrq = Txtjfrq.Text.Trim();
			_d50_mzmx.xmlx = Txtxmlx.Text.Trim();
			_d50_mzmx.yplx = Txtyplx.Text.Trim();
			_d50_mzmx.fylbid = Txtfylbid.Text.Trim();
			_d50_mzmx.jscs = Txtjscs.Text.Trim();
			_d50_mzmx.zfbl = Txtzfbl.Text.Trim();
			_d50_mzmx.yzxh = Txtyzxh.Text.Trim();
			_d50_mzmx.hzrq = Txthzrq.Text.Trim();
			_d50_mzmx.yjrq = Txtyjrq.Text.Trim();
			_d50_mzmx.zlje = Txtzlje.Text.Trim();
			_d50_mzmx.zlxz = Txtzlxz.Text.Trim();
			_d50_mzmx.bzxx = Txtbzxx.Text.Trim();
			_d50_mzmx.gldm1 = Txtgldm1.Text.Trim();
			_d50_mzmx.gldm2 = Txtgldm2.Text.Trim();
			_d50_mzmx.gldm3 = Txtgldm3.Text.Trim();
			_d50_mzmx.sjzt = int.Parse(TxtNumsjzt.Text.Trim());

            bool isok = false;
            if (Hid.Text.Length > 0)
                isok = mgr.Update_d50_mzmx(_d50_mzmx);
            else
                isok = mgr.Add_d50_mzmx(_d50_mzmx);
            if (isok)
            {
                d50_mzmx_Win.Hide();
                X.Msg.Notify("成功", "<font color='green'>恭喜您，操作成功！</font>").Show();
                log.Debug("d50_mzmx中执行了保存（插入或修改），并成功");
                d50_mzmx_Grid.Reload();
            }
            else
                X.Msg.Notify("失败", "<font color='red'>操作失败，请您重试！</font>").Show();
        }
        //数据保存为Excel
        protected void BtnSaveToExcel(object sender, EventArgs e)
        {
            string json = ExcelGridData.Value.ToString();
            StoreSubmitDataEventArgs eSubmit = new StoreSubmitDataEventArgs(json, null);
            XmlNode xml = eSubmit.Xml;
            this.Response.Clear();
            this.Response.ContentType = "application/vnd.ms-excel";
            this.Response.AddHeader("Content-Disposition", "attachment; filename=QiDian10Excel.xls");
            XslCompiledTransform xtExcel = new XslCompiledTransform();
            xtExcel.Load(Server.MapPath("/View/ExcelTemp/Excel.xsl"));
            xtExcel.Transform(xml, null, this.Response.OutputStream);
            this.Response.End();

        }
    }
}